/**
 * 获取窗口高度
 * @returns {number}
 */
window.getHeight= function(){
    if(window.innerHeight!= undefined){
        return window.innerHeight;
    }else{
        var B= document.body, D= document.documentElement;
        return Math.max(D.clientHeight, B.clientHeight);
    }
};
/**
 * 获取窗口宽度
 * @returns {number}
 */
window.getWidth= function(){
    if(window.innerWidth!= undefined){
        return window.innerWidth;
    }else{
        var B= document.body, D= document.documentElement;
        return Math.max(D.clientWidth, B.clientWidth);
    }
};

/**
 * 获取url上的参数
 * @param name
 * @returns {string|null}
 */
$.fn.param = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var params = window.location.hash.substring(1).split("?");
    if(params != null && params != undefined && params.length >= 2){
        var r = params[1].match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
    }
    return null;
};

/**
 * 解决IE浏览器不支持console，报错未定义问题
 * @type {Console}
 */
window.console = window.console || (function () {
    var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
        = c.clear = c.exception = c.trace = c.assert = function () { };
    return c;
})();

/**
 * 时间戳格式化方法
 * @param date
 * @param format
 * @returns {void | string}
 */
function dateFormat(date, format) {
    date = new Date(date);
    var map = {
        "M": date.getMonth() + 1, //月份
        "d": date.getDate(), //日
        "h": date.getHours(), //小时
        "m": date.getMinutes(), //分
        "s": date.getSeconds(), //秒
        "q": Math.floor((date.getMonth() + 3) / 3), //季度
        "S": date.getMilliseconds() //毫秒
    };
    format = format.replace(/([yMdhmsqS])+/g, function (all, t) {
        var v = map[t];
        if (v !== undefined) {
            if (all.length > 1) {
                v = '0' + v;
                v = v.substr(v.length - 2);
            }
            return v;
        } else if (t === 'y') {
            return (date.getFullYear() + '').substr(4 - all.length);
        }
        return all;
    });
    return format;
};

/**
 * HTML标签转义（< -> &lt;）
 */
function html2Escape(sHtml) {
    return $("<div/>").text(sHtml).html();
};

/**
 * HTML标签反转义（&lt; -> <）
 */
function escape2Html(str) {
    return $("<div/>").html(str).text();
}